<?php
interface SimpleDALinterface {

	function __construct($server = null, $connect = true, $force_new = true) ;
	function my_connect($server=null) ;
	function my_affected_rows($stmt = null) ;
	function my_query($sql='', $conn=null) ;
	function my_unbuffered_query ( $query, $conn = null ) ;
	function my_fetch_assoc($stmt=null) ;
	function my_fetch_array($stmt=null) ;
	function my_errno($conn = null) ;
	function my_error($conn = null) ;
	function my_select_db($db, $conn=null) ;
	function my_field_type ($result=null ,$field_offset=0) ;
	function my_free_result($stmt = null) ;
	function my_close($conn = null) ;
	function my_begin($conn = null) ;
	function my_autocommit($state = true, $conn = null) ;
	function my_commit($conn = null) ;
	function my_rollback($conn = null) ;
	function my_real_escape_string($string, $conn = null) ;
	function my_escape_string($string, $conn = null) ;

}

require_once('mysql.php');

class SimpleDAL {
	public static function factory($server = null, $connect = true, $force_new = true) {
		if(!isset($server)) throw new Exception('Server required');

		if(empty($server['rdbms_type'])) $server['rdbms_type'] = 'mysql';

		switch($server['rdbms_type']) {
			case 'mysql':
				return new MySQLDAL($server, $connect, $force_new);
				break;
			default:
				throw new Exception('Unsupported RDBMS: ' . $server['rdbms_type']);
		
		}
	}
}
